/**
 * @Description:
 * @Author: cnHuaShao
 * @File:  ConfigModel
 * @Version: 1.0.0
 */

package model

// 总配置文件模型
type Config struct {
	Http   HttpConf   `mapstructure:"http"`
	Server ServerConf `mapstructure:"server"`
	Redis  RedisConf  `mapstructure:"redis"`
	DB     DBConf     `mapstructure:"db"`
	LDAP   LDAPConf   `mapstructure:"ldap"`
}

// web服务配置
type HttpConf struct {
	HttpIp   string `mapstructure:"http_ip"`
	HttpPort string `mapstructure:"http_port"`
	HttpUrl  string `mapstructure:"http_url"`
}

// 服务配置
type ServerConf struct {
	ServerType string `mapstructure:"save_type"`
}

// redis配置
type RedisConf struct {
	RedisIp   string `mapstructure:"redis_ip"`
	RedisPort string `mapstructure:"redis_port"`
	RedisPwd  string `mapstructure:"redis_pwd"`
	RedisDB   int    `mapstructure:"redis_db"`
}

// 数据库配置
type DBConf struct {
	DBIp       string `mapstructure:"db_ip"`
	DBPort     string `mapstructure:"db_port"`
	DBName     string `mapstructure:"db_name"`
	DBUserName string `mapstructure:"db_username"`
	DBPWD      string `mapstructure:"db_pwd"`
}

// LDAP配置
type LDAPConf struct {
	LDAPUrl      string `mapstructure:"ldap_url"`
	LDAPUserName string `mapstructure:"ldap_username"`
	LDAPPWD      string `mapstructure:"ldap_pwd"`
	LDAPTimeout  string `mapstructure:"ldap_timeout"`
}

var Conf *Config

/**
初始基础配置文件，赋予默认值
*/
func NewConfig() *Config {
	return &Config{
		Http: HttpConf{
			"0.0.0.0",
			"8080",
			"http://127.0.0.1",
		},
		Server: ServerConf{
			"redis",
		},
		Redis: RedisConf{
			"127.0.0.1",
			"6379",
			"",
			1,
		},
		DB: DBConf{
			"127.0.0.1",
			"5432",
			"postgres",
			"postgres",
			"123456",
		},
		LDAP: LDAPConf{
			"",
			"",
			"",
			"",
		},
	}
}
